<?php
class BlogController extends AuthController{
	private $db;
	public function __init(){
		$this->db=new BlogModel;
	}
	// 显示栏目列表
	public function index(){
		$data =$this->db->getAll();
		$this->assign('data',$data['blog']);
		$this->assign('page',$data['page']);
		$this->display('index.html');
	}
	// 添加栏目
	public function add(){
		if(IS_POST){
			if($this->db->addblog()){
				$this->success('添加成功',__CONTROLLER__);
			}else{
				$this->error($this->db->error);
			}
		}else{
			//读取栏目
			$category = new CategoryModel;
			$categoryData= $category->getAll();
			$this->assign('categoryData',$categoryData);
			$this->display('add.html');
		}
	}
	//修改Blog
	public function edit(){
		if(IS_POST){
			if($this->db->editBlog()){
				$this->success('修改成功',__CONTROLLER__);
			}else{
				$this->error($this->db->error);
			}
		}else{
			// 读取博客
			$bid= $_GET['bid'];
			$field = $this->db->where('bid='.$bid)->find();
			// 分配栏目
			$catrgory = new CategoryModel;
			$categoryData= $category->getAll();
			//当前博客栏目为选中状态
			foreach($categoryData as $id=>$cat){
				$categoryData[$id]['selected']=$cat['cid']==$field['cid']?" selected=''":'';
			}
			$this->assign('categoryData',$categoryData);
			$this->assign('field',$field);
			$this->display('edit.html');
		}
	}
}





?>